
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "数据概览", icon: "dashboard", affix: true }
      }
    ]
  },

  {
    path: "/management",
    component: Layout,
    name: "management",
    meta: { title: "后台管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "",
        name: "User",
        component: () => import("@/views/management/index"),
        meta: { title: "用户", icon: "table" }
      },
      {
        path: "/menu",
        name: "menu",
        component: () => import("@/views/management/components/menu"),
        meta: { title: "菜单", icon: "tree" }
      },
      {
        path: "/permission",
        name: "Permission",
        component: () => import("@/views/management/components/permission"),
        meta: { title: "权限", icon: "table" }
      },
      {
        path: "journal",
        name: "Journal",
        component: () => import("@/views/management/components/journal"),
        meta: { title: "日志", icon: "tree" }
      }
    ]
  },

  {
    path: "/administration",
    component: Layout,
    children: [
      {
        path: " ",
        name: "administration",
        component: () => import("@/views/companys"),
        meta: { title: "企业管理", icon: "form" }
      }
    ]
  },

  {
    path: "/question-bank",
    component: Layout,
    name: "question-bank",
    meta: {
      title: "题库管理",
      icon: "nested"
    },
    children: [
      {
        path: "",
        name: "basics",
        component: () => import("@/views/question-bank/index"),
        meta: { title: "基础题库", icon: "table" }
      },
      {
        path: "/choiceness",
        name: "choiceness",
        component: () => import("@/views/question-bank/components/choiceness"),
        meta: { title: "精选题库", icon: "tree" }
      },
      {
        path: "/entering",
        name: "entering",
        component: () => import("@/views/question-bank/components/entering"),
        meta: { title: "试题录入", icon: "table" }
      },
      {
        path: "/list",
        name: "list",
        component: () => import("@/views/question-bank/components/list"),
        meta: { title: "组题列表", icon: "tree" }
      }
    ]
  },
  {
    path: "/external-link",
    component: Layout,
    name: "external-link",
    meta: {
      title: "学科管理",
      icon: "nested"
    },
    children: [
      {
        path: "",
        name: "subject",
        component: () => import("@/views/external-link/index"),
        meta: { title: "学科", icon: "table" }
      },
      {
        path: "/catalogue",
        name: "catalogue",
        component: () => import("@/views/external-link/components/catalogue"),
        meta: { title: "目录", icon: "tree" }
      },
      {
        path: "/label",
        name: "label",
        component: () => import("@/views/external-link/components/label"),
        meta: { title: "标签", icon: "table" }
      }
    ]
  },
  {
    path: "/skill",
    component: Layout,
    children: [
      {
        path: "",
        name: "skill",
        component: () => import("@/views/skill/index"),
        meta: { title: "面试技巧", icon: "form" }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
